package cn.cool.springframework.beans.factory.support;

import cn.cool.springframework.beans.BeansException;
import cn.cool.springframework.beans.factory.config.BeanDefinition;

public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory {
    /**
     * 反射去创建 bean（但是要分是cglib创建还是jdk反射创建）
     */
    @Override
    protected Object createBean(String beanName, BeanDefinition beanDefinition) throws BeansException {
        // 获取 bean定义信息中的class对象，创建对象并且返回
        Object bean = null;
        try {
            bean = beanDefinition.getBeanClass().newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new BeansException("Instantiation of bean failed", e);
        }
        // 缓存单例对象
        addSingleton(beanName, bean);
        return bean;
    }
}
